home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvtools / demos / citydemo / c4i_rebind.c < prev    next >
C/C++ Source or Header  |  1997-05-08  |  4KB  |  168 lines

  1. #ifndef lint
  2. static char SccsId[]= "@(#)c4i_rebind.c    V1.10    3/13/95";
  3. #endif
  4.  
  5. /*------------------------------------------------------------------
  6. | file name -- c4i_rebind.c
  7. |
  8. | functions        Description
  9. | ---------        -----------
  10. |
  11. | InitDataTable        Initialize the name:data table for rebinding.
  12. | RebindData        Rebinds DV-Draw variables to Application Data.
  13. | rebind        Local.  Slectively rebinds VDPs to application buffers.
  14. | TermDataTable        Cleans up the name:data table.
  15. |
  16. | GetVdp        Returns the vdp associated with the object.
  17. |-----------------------------------------------------------------*/
  18.  
  19. #include "std.h"
  20. #include "dvstd.h"
  21. #include "dvtools.h"
  22. #include "VOstd.h"
  23. #include "Tfundecl.h"
  24. #include "c4i_vars.h"
  25. #include "c4i_data.h"
  26. #include "VGfundecl.h"
  27. #include "VTfundecl.h"
  28. #include "c4i_fundecl.h"
  29.  
  30.  
  31.  
  32. /***************** Begin Function Declarations *************/
  33. LOCAL  ADDRESS rebind V_P_((OBJECT vd_obj, ADDRESS vdp, ADDRESS args));
  34. LOCAL  ADDRESS return_vdp V_P_((OBJECT vd_obj, ADDRESS vdp, ADDRESS args));
  35. CHAR *VIstrclone V_P_((char*));          /* Internal function: allocates & copies a string */
  36. /***************** End Function Declarations *************/
  37.  
  38. /*-----------------------------------------------------------------
  39. |
  40. |  InitDataTable
  41. |       Initialize the Data Table.  The Data Table is a symbol table of
  42. |       variable names and their data buffer.  This table is used by
  43. |       DV-Tools to rebind DV-Draw variables to application data.
  44. */
  45. void InitDataTable 
  46. V_P_ ((void))
  47. {
  48.   INT i;
  49.  
  50.   /* Create the symbol table */
  51.   DataTable = VTstcreate ("Data Name and Info", (VTSTCOMPAREFUNPTR)NULL);
  52.  
  53.   /* Make entries for the name buffer pairs defined by DataTable
  54.   |  in c4i_data.c
  55.   */
  56.   for (i = 0; i < MAX_APP_VARS; i++)
  57.     {
  58.       (VOID) VTstsninsert (DataTable,
  59.                            VIstrclone (DataInfo[i].varname),
  60.                            (INT *) & DataInfo[i]);
  61.     }
  62. }
  63.  
  64.  
  65. /*-----------------------------------------------------------------
  66. |
  67. |  RebindData
  68. |    Traverses the view's vdps, checking to see if they need to
  69. |    be rebound to real-time data buffers.
  70. |
  71. */
  72. void 
  73. RebindData (view)
  74.      VIEW view;
  75. {
  76.  
  77.   /* Rebind all the vdps that match the table of real-time data.
  78.   |  Get the drawing from the view and then all rebind() for
  79.   |  all the variables.
  80.   */
  81.   (VOID) TobForEachVdp (TviGetDrawing (view), rebind, (ADDRESS) NULL);
  82. }
  83.  
  84. /*-----------------------------------------------------------------
  85. |
  86. |  rebind
  87. |    Gets the vdp's name, if it matches one in the DataTable, rebind
  88. |    the buffer to the real-time buffer.
  89. */
  90. /* ARGSUSED */
  91. LOCAL ADDRESS 
  92. rebind (vd_obj, vdp, args)
  93.      OBJECT vd_obj;
  94.      ADDRESS vdp;
  95.      ADDRESS args;
  96. {
  97.   CHAR *varname;
  98.   SYMNODE node;
  99.   DATA_INFO *data_info;
  100.  
  101.   /* Get the vdp's name */
  102.   varname = VGvdvarname (vdp);
  103.  
  104.   /* See if the name is in the Table of Application Variables */
  105.   node = VTstkeyfind (DataTable, varname);
  106.   if (node)
  107.     {
  108.       /* Rebind the data to the application buffer */
  109.       data_info = (DATA_INFO *) VTsnvalue (node);
  110.       (VOID) TvdPutBuffer (vdp, data_info->bufptr);
  111.     }
  112.   return NULL;
  113. }
  114.  
  115. /*-----------------------------------------------------------------
  116. |
  117. |  TermDataTable
  118. */
  119. void TermDataTable 
  120. V_P_ ((void))
  121. {
  122.   CHAR *varname;
  123.   SYMNODE node;
  124.  
  125.   /* Destroy the strings cloned in the table */
  126.   while (VTstlen (DataTable) > 0)
  127.     {
  128.       node = VTstsnget (DataTable, 0);
  129.       varname = VTsnkey (node);
  130.       S_FREE (varname);
  131.       VTstsnremove (DataTable, node);
  132.     }
  133.  
  134.   /* Destroy the table itself */
  135.   VTstdestroy (DataTable);
  136. }
  137.  
  138. /*------------------------------------------------------------------
  139. |
  140. | GetVdp
  141. |       Uses TobForEachVdp to return object's vdp. This function assumes
  142. |       the object only has one vdp.
  143. */
  144. ADDRESS 
  145. GetVdp (obj)
  146.      OBJECT obj;
  147. {
  148.  
  149.   /* Call return_vdp() for each vdp, this function assumes only one vdp */
  150.   return (VARDESC) TobForEachVdp (obj, return_vdp, (ADDRESS) NULL);
  151. }
  152.  
  153. /*-----------------------------------------------------------------
  154. |
  155. |  return_vdp
  156. |       Returns the passed in vdp, this funciton is called from
  157. |       inside of TobForEachVdp().
  158. */
  159. /* ARGSUSED */
  160. LOCAL ADDRESS 
  161. return_vdp (vd_obj, vdp, args)
  162.      OBJECT vd_obj;
  163.      ADDRESS vdp;
  164.      ADDRESS args;
  165. {
  166.   return vdp;
  167. }
  168.